//
//  ShowViewController.m
//  XiJianChui
//
//  Created by Mac on 16/7/19.
//  Copyright © 2016年 FanShuHan. All rights reserved.
//

#import "ShowViewController.h"
#import "ShowTopView.h"
#import "HomerViewController.h"
#import "LeaderBoardVC.h"
#import "FaxingVC.h"

@interface ShowViewController ()

@property(nonatomic,weak) ShowTopView *topView;
@property(nonatomic,weak) UIImageView *leftImageView;
@property(nonatomic,weak) UIImageView *rightImageView;

@end

@implementation ShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"主页";
    self.view.backgroundColor = QhColor(239, 239, 244);
    [self addTopView];
    [self addTwoImageView];
    [self setRightBarButtonItem];
    
}

//添加上部view
- (void)addTopView {
    ShowTopView *topView = [ShowTopView topView];
    topView.frame = CGRectMake(0, 64, QhScreenW, 300);
    self.topView = topView;
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jumpToLeaderVC)];
    [topView addGestureRecognizer:tap];
    [self.view addSubview:topView];
}

//实现手势方法
- (void)jumpToLeaderVC {
//    NSLog(@"%s",__func__);
    LeaderBoardVC *lbVC = [[LeaderBoardVC alloc] init];
    [self.navigationController pushViewController:lbVC animated:YES];
}

//添加下面两个imageview
- (void)addTwoImageView {
    CGFloat margin = 40;
    CGFloat x1 = 50;
    CGFloat y = self.topView.bounds.size.height + 64;
    CGFloat w = 120;
    CGFloat h = 180;
    CGFloat x2 = QhScreenW - x1 - w;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y, QhScreenW, QhScreenH - y)];
//    view.backgroundColor = [UIColor whiteColor];
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jumpToFaxingVC)];
    [view addGestureRecognizer:tap];
    
//    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x1, y, w, h)];
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x1, margin, w, h)];
    leftImageView.backgroundColor = [UIColor yellowColor];
    [leftImageView setImage:[UIImage imageNamed:@"mingren"]];
    self.leftImageView = leftImageView;
//    [self.view addSubview:leftImageView];
    [view addSubview:leftImageView];
    
//    UIImageView *rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x2, y, w, h)];
    UIImageView *rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x2, margin, w, h)];

    rightImageView.backgroundColor = [UIColor yellowColor];
    [rightImageView setImage:[UIImage imageNamed:@"chutian"]];
    self.rightImageView = rightImageView;
//    [self.view addSubview:rightImageView];
    [view addSubview:rightImageView];
    [self.view addSubview:view];
}

- (void)jumpToFaxingVC {
    NSLog(@"%s",__func__);
    FaxingVC *vc = [[FaxingVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//设置导航栏右边按钮
- (void)setRightBarButtonItem {
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 44, 44);
    [rightBtn setImage:[UIImage imageNamed:@"geren"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [view addSubview:rightBtn];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    self.navigationItem.rightBarButtonItem = rightItem;
}

//rightBtn点击事件
- (void)rightBtnClick {
//    NSLog(@"%s",__func__);
    HomerViewController *homeVC = [[HomerViewController alloc] init];
    [self.navigationController pushViewController:homeVC animated:YES];
}

@end


